﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TroopLeaderManager : MonoBehaviour
{

    public List<TroopLeader> troopLeaders = new List<TroopLeader>();
    private static TroopLeaderManager instance;
    public static TroopLeaderManager Instance
    {
        get
        {
            return instance;
        }
    }

    public void Awake()
    {
        if (instance == null) instance = this;
        else if (instance != this)
        {
            Destroy(this);
            return;
        }

    }

    public void Enroll(TroopLeader leader)
    {
        troopLeaders.Add(leader);
    }
    public void Disenroll(TroopLeader leader)
    {
        troopLeaders.Remove(leader);
    }

    public TroopLeader GetNearestTroopLeader(Vector3 position, PlayerType troopOwner)
    {
        System.Comparison<TroopLeader> closer = (x, y) => (x.troopOwner == troopOwner && x.isActiveAndEnabled) && (x.transform.position - position).sqrMagnitude < (y.transform.position - position).sqrMagnitude ? 1 : -1;
        return troopLeaders.MQ_Max(closer);
    }
}
